Help:HTML in wikitext
For many HTML elements, more convenient wikitext code is available, see , however there are some situations in which the HTML alternative is useful, for example creating a link to a particular element of a table. Permitted HTML The following HTML elements are currently permitted: ; HTML element#General : An abbreviation (e.g., Abbr., HTML) ; HTML element#Presentation : Text stylistically offset from other text without conveying extra importance ; HTML element#Presentation (deprecated) : Indicates representation in a larger font size ; HTML element#Other block elements : A section of quoted material, usually presented as an indented block, typically for long quotes ; HTML element#Other inline elements : A line break in the middle of text such as poetry or addresses ; HTML element#Tables : A table caption ; HTML element#Other block elements (deprecated) : Indicates presentation as a block-level center-aligned division ; HTML element#Other inline elements : Title of a work (e.g., ) ; HTML element#Computer phrase elements : A fragment of computer code ; HTML element#Lists : A value in a -marked association list ; HTML element#Other block elements : Indicates a deletion ; HTML element#General : Marks a defined term: a term that is defined in the nearby text. ; HTML element#Other block elements : A division of text, usually presented as a block ; HTML element#Lists : An association list of names corresponding to values (e.g., terms and definitions, or properties and data) ; HTML element#Lists : A name in a -marked association list ; HTML element#General : A tag for stressing emphasis ; HTML element#Presentation (deprecated) : Indicates presentation with a particular font color, typeface and/or size. ; HTML element#Basic text - HTML element#Basic text : Section headings at different levels. ; HTML element#Other block elements : A paragraph-level thematic break such as a transition to a different topic Usually represented by a horizontal line. ; HTML element#Presentation : Text which is represented in an alternate voice or mood, usually represented by italics ; HTML element#Other block elements : Indicates an insertion ; HTML element#Computer phrase elements : Indicates text to be entered by the user. ; HTML element#Lists : A list item in ordered (ol) or unordered (ul) lists ; HTML element#Lists : An ordered... (enumerated) list ; HTML element#Basic text : Indicates a paragraph or paragraph break. (Paragraphs are usually indicated by .) ; HTML element#Other block elements : Represents a block of pre-formatted text ; Ruby character#Ruby markup : 東 vs 東 ; Ruby character#Ruby markup : ( vs ( ; Ruby character#Ruby markup : とう vs とう ; Ruby character#Ruby markup : 東(とう)京(きょう) vs 東(とう) 京(きょう) ; HTML element#Computer phrase elements : Represents a sample output, such as from a program or script. ; (preferred) or (obsolete) : Indicates text that is no longer valid or relevant ; HTML element#Presentation : Indicates fine print such as legal disclaimers in advertising ; HTML element#Span : A division of text, usually presented inline with surrounding text ; HTML element#General : Stresses strong importance, usually presented in bold ; HTML element#Other inline elements : Indicates asubscript ; HTML element#Other inline elements : Indicates asuperscript ; HTML element#Tables (deprecated) : Indicates presentation in a fixed-width font ; HTML element#Presentation : Indicates a non-textual annotation, typically represented as underlining ; HTML element#Lists : An unordered... (bulleted) list ; HTML element#Computer phrase elements : Indicates a variable ; HTML element#Comments (will be stripped during processing) : Anchors HTML tags allow an id attribute that can be referenced in one's CSS, and allows the element to be used as link target. However, the anchor element a is not allowed, so the wikitext Main Page is treated like the wikitext <a href="http://meta.wikimedia.org/">Main Page</a> and is therefore displayed as which is unlikely to be what the editor intended. Instead of using the anchor element () the wiki markup for external reference is required (enclosed in square brackets with the URL separated from the contents by a single space): Main Page displays as The following excerpt from Sanitizer.php additionally shows which attributes are allowed. $htmlpairsStatic = array( # Tags that must be closed 'b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's', 'strike', 'strong', 'tt', 'var', 'div', 'center', 'blockquote', 'ol', 'ul', 'dl', 'table', 'caption', 'pre', 'ruby', 'rt' , 'rb' , 'rp', 'p', 'span', 'u', 'abbr' ); $htmlsingle = array( 'br', 'hr', 'li', 'dt', 'dd' ); $htmlsingleonly = array( # Elements that cannot have close tags 'br', 'hr' ); $htmlnest = array( # Tags that can be nested--?? 'table', 'tr', 'td', 'th', 'div', 'blockquote', 'ol', 'ul', 'dl', 'font', 'big', 'small', 'sub', 'sup', 'span' ); $tabletags = array( # Can only appear inside table, we will close them 'td', 'th', 'tr', ); $htmllist = array( # Tags used by list 'ul','ol', ); $listtags = array( # Tags that can appear in a list 'li', ); Tags is a generic inline text container. ' is a similar tag which is deprecated (should not be used) in favor of .'' For example a red word. produces the same result as a red word. See also and m:Help:Text color. It's pointless to combine the legacy tag with inline CSS; legacy browsers would ignore the CSS, while modern browsers support (see above). Note that in most cases, one can use a more descriptive tag, for instance, to indicate an important piece of text, or (subject to the same things as strong) to indicate an emphasized piece of text. This not only draws the user's attention to the text, but can also alert those who are using nonvisual browsers or have sight impairments, etc. to the fact that that is emphasized text. Using as a link target The standard way of providing a named anchor as an invisible target (i.e. ) doesn't work (since all tags are converted), and an alternative suggested by the W3C, , produces an "Edit" link. However, does produce a target that can be the destination of a link. (This is silently changed to ). This is the method used by the template. Note that it doesn't work everywhere; for instance, in a table, it has to be inside a cell before some browsers will jump to it properly. This technique can be used to produce immutable links from one article to a section of another, which continue to work even if the section name is changed by someone who does not realize that another article links there. For example, . ' ' is a generic block container. Rules: * should be followed by a newline * should be preceded by a newline * followed by text on the same line, two newlines and text before on the same line should be avoided (because the two newlines only produce a space) HTML comment Using : * *" " gives "start-pqr-end", producing HTML code without the comment. The "Remove comments" option of ExpandTemplates selects whether comments are removed, not just in the final result but throughout the expansion process. This affects the result of parser functions: a comment in the expression of #expr or in the condition of #ifexpr gives an error message unless "Remove comments" is on, and comments affect #if and #ifeq. Example: Wikitext: ---- ---- Result of normal expansion, and of ExpandTemplates with "Remove comments" on: ---- ---- Result of full substitution, and of ExpandTemplates with "Remove comments" off: ---- 0 0 1 Therefore it is typically better to avoid comments in these places, and to put the comment before or after the parser function. In the case of nested parser functions, to avoid having to put the comments outside the whole, an alternative is . In the case of substitution of the parser function, "void" has to be substituted too, e.g. in a template allowing multi-level substitution we can put }#expr:3* } }void| multiply by 3 }}}}. Another alternative is making the comment the name of a parameter (in the likely case that it is unused), with the empty string as default, e.g. } or, to recognize the intention, use pseudo comment tags: }, or real ones, if the empty string is not used as parameter: }. See also . Attributes Most tags can have a style attribute. For example This is red text. produces: This is red text. Most tags can have classes and IDs. They can be used in conjunction with stylesheets to give a piece of text a descriptive class (or unique identifier) and to refer to that in a stylesheet. For example Example infobox Example infobox Produces the box which floats on the right because infobox class is already defined in local Mediawiki:Common.css. Classes and IDs can also be used by Javascript code, for example see how {Link FA} works in enwiki. Classes are also widely used to create microformats. See the microformats project for more information. Some class names are reserved for use in microformats. Another attribute example is title, for example used in template: note the hover box over "20000 ft" "a height of above sea level" Tags with special effect Pre tags work as the combination of and the standard HTML tag: the content will preformatted, and it will not be parsed, but shown as in the wikitext source. If you want preformatted but parsed text, use a space in the beginning of the line instead. For example, This word is bold. This word is bold. will render as This word is bold. This word is bold. Comments HTML comments in the wikitext () will not appear in the HTML code at all. Headers Headers ( ... ) will be treated in a similar way as wikicode headers: sample header Note that it appears in the table of contents and has an accompanying edit link. There are some minor differences though: editing such a section won't prefill the edit summary, and the browser won't jump to the beginning of the section when saving the page. Thus, you should use the wikitext equivalents instead. Exceptions In some pages in the MediaWiki namespace (typically the short messages like button labels) HTML does not work, and e.g. produces the HTML <span id=abc> rendered by the browser as . Some others are interpreted as pure HTML (thus any tag can be used, but wikicode won't be transformed to HTML). User CSS and JS pages (see ) are interpreted as if inside a block. From MW 1.11 this also goes for sitewide CSS/JS; in earlier versions, you have to manually add /* */ to the beginning and /**/ to the end of those pages to avoid strange rendering. Validation The MediaWiki software attempts to catch HTML errors, but it does not catch all of them. If you use HTML in wikitext, it is helpful to verify it with the W3C Markup Validation Service. See also *Wikipedia:Span tags External links * HTML 4.01 specification: elements | attributes * For customizing the handling of HTML in MediaWiki, see the HTML and Tidy sections in mw:Manual:Configuration settings * Some extensions allow adding arbitrary HTML to a page, for example mw:Extension:AddHTML, mw:Extension:SecureHTML and mw:Extension:Secure HTML; see $wgRawHtml for a more complete list * Within the MediaWiki codebase, these HTML checks happen in includes/Sanitizer.php Category:Editor handbook Category:Wikipedia editor help pl:Pomoc:Używanie kodu HTML pt:Ajuda:HTML sv:Wikipedia:Taggar zh:Help:HTML ]] : Identifies a table ; HTML element#Tables : A table data cell ; HTML element#Tables : A table header cell; contents are conventionally displayed bold and centered ; HTML element#Tables : Contains a row of cells in a table ; [[HTML element#Presentation|